//
//  JYJDataTools.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/6.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJDataTools.h"
#import "JYJProgramModel.h"
#import "JYJTAMacro.h"
#import "JYJNetWorkParser.h"

@implementation JYJDataTools
+ (instancetype)shareDataTools {
    static JYJDataTools *dataTools = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dataTools = [[JYJDataTools alloc]init];
    });
    return dataTools;
}
- (void)postDataWithURL:(NSString *)URL andBody:(id)body passValue:(PassValue)passvalue {
    [JYJNetWorkParser POST:URL andBody:body andBodyStyle:JYJBodyString andHeader:HEADDIC andResponse:JYJJSON andSuccessBlock:^(id result) {
        self.dataArray = [NSMutableArray array];
        NSArray *dataArray = [result objectForKey:@"data"];
        for (NSDictionary *dic in dataArray) {
            JYJProgramModel*model = [JYJProgramModel modelWithDic:dic];
            [self.dataArray addObject:model];
        }
        // ！！！！！block回调
        passvalue(self.dataArray);
        
    } andFailureBlock:^(NSError *error) {
        
    }];
    

}
- (JYJProgramModel *)getModelWithIndex:(NSInteger)index {
    return self.dataArray[index];
}
@end
